package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.Pays;
import metier.entities.SubCategorie;


@Stateless(name="SubCategorie")
public class SubCategorieEJBImpl implements ISubCategorieLocal,ISubCategorieRemote{
	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;

	@Override
	public void addSubCategorie(SubCategorie subc) {
		
		em.merge(subc);
	}

	@Override
	public List<SubCategorie> getAllSubCategories() {
		Query req=em.createQuery("select sb from SubCategorie sb");
		return req.getResultList();
	}
	
	@Override
	public List<SubCategorie> getAllActiveSubCategories() {
		Query req=em.createQuery("select sb from SubCategorie sb where sb.Statut=true");
		return req.getResultList();
	}

	@Override
	public SubCategorie getSubCategorie(Integer Id) {
		SubCategorie sb=em.find(SubCategorie.class, Id);
		return  sb;
	}

	@Override
	public void updateSubCategories(SubCategorie subc) {
		em.merge(subc);
		
	}

	@Override
	public void deleteSubCategorie(Integer Id) {
		SubCategorie sb=getSubCategorie(Id);
		em.remove(sb);
		
	}

}
